package org.kabeja.dxf.helpers;

import org.kabeja.math.MathUtils;

/**
 * @author shutao
 * @since 2022/4/25 10:16
 */
public class ParametricLine {
    protected Point startPoint;
    protected Vector direction;

    public ParametricLine(Point var1, Vector var2) {
        this.startPoint = var1;
        this.direction = var2;
    }

    public ParametricLine(Point var1, Point var2) {
        this.startPoint = var1;
        this.direction = MathUtils.getVector(var1, var2);
    }

    public ParametricLine() {
        this(new Point(), new Point());
    }

    public double getIntersectionParameter(ParametricLine var1) {
        Vector var2 = MathUtils.crossProduct(this.direction, var1.getDirectionVector());
        if (MathUtils.absoluteValue(var2) == 0.0D) {
            return Double.POSITIVE_INFINITY;
        } else {
            Vector var3 = MathUtils.crossProduct(MathUtils.getVector(this.startPoint, var1.getStartPoint()), var1.getDirectionVector());
            double var4 = 0.0D;
            if (var2.getX() != 0.0D) {
                var4 = var3.getX() / var2.getX();
            } else if (var2.getY() != 0.0D) {
                var4 = var3.getY() / var2.getY();
            } else if (var2.getZ() != 0.0D) {
                var4 = var3.getZ() / var2.getZ();
            }

            return var4;
        }
    }

    public Point getStartPoint() {
        return this.startPoint;
    }

    public void setStartPoint(Point var1) {
        this.startPoint = var1;
    }

    public Vector getDirectionVector() {
        return this.direction;
    }

    public void setDirectionVector(Vector var1) {
        this.direction = var1;
    }

    public Point getPointAt(double var1) {
        return MathUtils.getPointOfStraightLine(this.startPoint, this.direction, var1);
    }

    public double getParameter(Point var1) {
        double var2 = 0.0D;
        if (this.direction.getX() != 0.0D) {
            var2 = (var1.getX() - this.startPoint.getX()) / this.direction.getX();
        } else if (this.direction.getY() != 0.0D) {
            var2 = (var1.getY() - this.startPoint.getY()) / this.direction.getY();
        } else if (this.direction.getZ() != 0.0D) {
            var2 = (var1.getZ() - this.startPoint.getZ()) / this.direction.getZ();
        }

        return var2;
    }
}
